<?php

/**
 * This is the model class for table "zy_rate".
 *
 * The followings are the available columns in table 'zy_rate':
 * @property integer $id
 * @property integer $agent_type
 * @property integer $package_id
 * @property string $rate
 * @property integer $is_delete
 * @property string $createtime
 * @property integer $creater
 * @property integer $updater
 * @property string $updatetime
 * @property string $remark
 */
class Rate extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Rate the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'zy_rate';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('rate', 'required'),
			array('agent_type, package_id, is_delete, creater, updater', 'numerical', 'integerOnly'=>true),
			array('rate', 'length', 'max'=>11),
			array('remark', 'length', 'max'=>255),
			array('createtime, updatetime', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, agent_type, package_id, rate, is_delete, createtime, creater, updater, updatetime, remark', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'agent_type' => Yii::t('base','Agent Type'),
			'package_id' => Yii::t('base','Package'),
			'rate' => Yii::t('base','Rate'),
			'is_delete' =>Yii::t('base','Is Delete'),
			'createtime' => Yii::t('base','Createtime'),
			'creater' => Yii::t('base','Creater'),
			'updater' => 'Updater',
			'updatetime' => 'Updatetime',
			'remark' => 'Remark',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('agent_type',$this->agent_type);
		$criteria->compare('package_id',$this->package_id);
		$criteria->compare('rate',$this->rate,true);
		$criteria->compare('is_delete',$this->is_delete);
		$criteria->compare('createtime',$this->createtime,true);
		$criteria->compare('creater',$this->creater);
		$criteria->compare('updater',$this->updater);
		$criteria->compare('updatetime',$this->updatetime,true);
		$criteria->compare('remark',$this->remark,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function updaterate(){
		$package_id=$_POST['Rate']['package_id'];
		$agent_type=$_POST['Rate']['agent_type'];
		$rate=Rate::model()->find('package_id='.$package_id.' AND agent_type='.$agent_type.' AND is_delete=0');
		$rate->is_delete=1;
		$rate->update();
		return $rate;
	}
	public function getIsdelete($id){
		if($id==0){
			return '正在使用';
		}else{
			return '过期';
		}
	}
}